package seatiger.tomcat.catalina.connector;

import seatiger.tomcat.catalina.*;
import seatiger.tomcat.catalina.connector.http.HttpRequestImpl;
import seatiger.tomcat.catalina.connector.http.HttpResponseImpl;
import seatiger.tomcat.catalina.util.LifecycleSupport;

import java.util.List;

/**
 *
 */
public abstract class AbstractConnector implements Connector, Lifecycle {
    protected LifecycleSupport lifecycle = new LifecycleSupport(this);
    protected String scheme = "http";
    protected volatile boolean initialized = false;
    protected volatile boolean started = false;
    /**
     * 关联容器
     */
    protected Container container;

    protected Service service;

    @Override
    public Request createRequest() {
        HttpRequestImpl request = new HttpRequestImpl();
        request.setConnector(this);
        return request;
    }

    @Override
    public abstract void initialize() throws LifecycleException;

    @Override
    public abstract void start() throws LifecycleException;

    @Override
    public abstract void stop() throws LifecycleException;

    @Override
    public void setContainer(Container container) {
        this.container = container;
    }

    @Override
    public Container getContainer() {
        return container;
    }

    @Override
    public void setService(Service service) {
        this.service = service;
    }

    @Override
    public Service getService() {
        return service;
    }

    @Override
    public String getScheme() {
        return scheme;
    }

    @Override
    public void setScheme(String scheme) {
        this.scheme = scheme;
    }

    @Override
    public void addLifecycleListener(LifecycleListener listener) {
        lifecycle.addLifecycleListener(listener);
    }

    @Override
    public List<LifecycleListener> findLifecycleListeners() {
        return lifecycle.findLifecycleListeners();
    }

    @Override
    public void removeLifecycleListener(LifecycleListener listener) {
        lifecycle.removeLifecycleListener(listener);
    }

    @Override
    public Response createResponse() {
        HttpResponseImpl response = new HttpResponseImpl();
        return response;
    }
}
